//package com.example.dmcommom.redis;
//
//import com.example.dmcommom.RedisUtils;
//import com.fasterxml.jackson.annotation.JsonAutoDetect;
//import com.fasterxml.jackson.annotation.PropertyAccessor;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.boot.context.properties.EnableConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
//import org.springframework.data.redis.serializer.StringRedisSerializer;
//
//@Configuration
//@EnableConfigurationProperties(RedisConfig.class)
//@ConditionalOnProperty(prefix = "spring.redis", name = "open", havingValue = "true")
//public class RedisPropertiesAutoConfig {
//
//    /**
//     * 可覆盖此配置
//     *
//     * @return
//     */
//    @Bean
//    @ConditionalOnMissingBean
//    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
//        RedisTemplate<String, Object> redisTemplate = new RedisTemplate();
//        redisTemplate.setConnectionFactory(redisConnectionFactory);
//        //用于值序列化，反序列化
//        Jackson2JsonRedisSerializer jsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
//
//        ObjectMapper objectMapper = new ObjectMapper();
//        objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
//        objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
//
//        jsonRedisSerializer.setObjectMapper(objectMapper);
//
//        //用于key序列化，反序列化
//        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
//
//        //key
//        redisTemplate.setKeySerializer(stringRedisSerializer);
//        redisTemplate.setHashKeySerializer(stringRedisSerializer);
//
//        //value
//        redisTemplate.setValueSerializer(jsonRedisSerializer);
//        redisTemplate.setHashValueSerializer(jsonRedisSerializer);
//
//        redisTemplate.afterPropertiesSet();
//
//        return redisTemplate;
//    }
//
//    /**
//     * 可覆盖此配置
//     *
//     * @param redisTemplate
//     * @return
//     */
//    @Bean
//    @ConditionalOnMissingClass
//    public RedisUtils redisUtil(RedisTemplate<String, Object> redisTemplate) {
//        return new RedisUtils(redisTemplate);
//    }
//}
